<template>
  <div>
    <el-form :model="form">
      <el-form-item label="活动名称" label-width="120px">
        {{ editUserId }}
        <el-input v-model="form.nickName" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="岗位" label-width="120px">
        {{ postIds }}
        <el-select v-model="postIds" multiple>
          <el-option v-for="p in postList" :key="p.postId" :label="p.postName" :value="p.postId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="部门" label-width="120px">
        {{ form.deptId }}
        <el-select class="main-select-tree" ref="selectTree" v-model="form.deptId" style="width: 560px;">
          <el-option v-for="item in deptList" :key="item.deptId" :label="item.deptName" :value="item.deptId"
                     style="display: none;"/>
          <el-tree class="main-select-el-tree" ref="selecteltree"
                   :data="deptTree"
                   node-key="deptId"
                   highlight-current
                   :props="{
        children: 'children',
        label: 'deptName',value:'deptId'
      }"
                   @node-click="handleNodeClick"
                   current-node-key="deptId"
                   default-expand-all/>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="$emit('input', false)">取 消{{ value }}11</el-button>
      <el-button type="primary" @click="subForm">确 定</el-button>
    </div>
  </div>
</template>

<script>
import request from "@/util/request";

export default {
  methods: {
    subForm() {
      this.form.postIds = this.postIds;
      request("user", "put", this.form).then(() => {
        this.$emit('changeDialogFormVisible', true)
      })
    },
    // 四级菜单
    handleNodeClick(node) {
      this.form.deptId = node.deptId;
      this.$refs.selectTree.blur();
    }
  },
  props: ["editUserId", "value"],
  name: "UserEdit",
  async created() {
    this.deptTree = await request("dept/tree")
    this.deptList = await request("dept")
    this.postList = await request("post")
    if (this.editUserId) {
      this.form = await request("user/" + this.editUserId)

      this.postIds = this.form.postList.map(o => {
        return o.postId
      })

    }
  },
  data() {
    return {
      form: {},
      postIds: [],
      dialogFormVisible: false,
      options: [],
      deptList: [],
      deptTree: [],
      postList: []

    }
  }
}
</script>

<style scoped>

</style>